<template>
  <div class="box6">
    <div class="title">
      <p>热门景区排行</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

//DOM节点
let charts = ref()
onMounted(() => {
  let mycharts = echarts.init(charts.value)
  mycharts.setOption({
    title: {
      text: '景区排行',
      left: '50%',
      //超链接
      link: 'https://echarts.apache.org/zh/option.html#title.subtextStyle.fontStyle',
      //主标题文字样式
      textStyle: {
        color: 'yellowgreen',
        fontSize: 20,
      },
      //子标题
      subtext: '各大景区排行',
      //子标题样式
      subtextStyle: {
        color: 'white',
        fontSize: 14,
        align: 'center',
      },
    },
    xAxis: {
      show: false,
    },
    yAxis: {
      show: false,
      type: 'category',
    },
    grid: {
      left: 150,
      top: 70,
      right: 120,
      bottom: 20,
    },
    series: [
      {
        type: 'bar',
        data: [10, 20, 30, 40, 50, 60],
        label: {
          show: true,
        },
        barWidth: '50%',
        barGap: '10%',
        //排序
        realtimeSort: false,
        //是否显示背景颜色
        showBackground: true,
        backgroundStyle: {
          borderRadius: 30,
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'black', // 0% 处的颜色
              },
              {
                offset: 1,
                color: 'blue', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        },
        //柱条样式
        itemStyle: {
          borderRadius: 30,
          color: function (data: any) {
            // 给每一个柱条不同的颜色
            let arr = [
              'red',
              'orange',
              'yellowgreen',
              'green',
              'blue',
              'skyblue',
            ]
            return arr[data.dataIndex]
          },
        },
      },
    ],
    //提示框
    tooltip: {
      show: true,
    },
  })
})
</script>

<style scoped lang="scss">
.box6 {
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 10px 0;

  .title {
    color: white;
    padding-left: 20px;
  }

  .charts {
    width: 100%;
    height: 100%;
  }
}
</style>
